package com.Home
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	import com.UI.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameHomeDispatch extends JFrame
	{
		//members define
		private var panel13:JPanel;
		private var btn_tab_slave:JToggleButton;
		private var btn_tab_lover:JToggleButton;
		private var btn_tab_pet:JToggleButton;
		private var panelOption0:PaneHomeDispatchOption;
		private var panelOption1:PaneHomeDispatchOption;
		private var panelOption2:PaneHomeDispatchOption;
		private var panelBCenter:JPanel;
		private var btnPrev:JButton;
		private var labelPage:JLabel;
		private var btnNext:JButton;
		
		private var btn_close:JButton;
		public function FrameHomeDispatch()
		{
			setResizable(false);
			setBorder(new EmptyBorder());
			
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(198, 0));
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			this.getTitleBar().setCloseButton(btn_close);
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
			getTitleBar().getFrame().setClipMasked(false);
			btn_close.setClipMasked(false);
			getTitleBar().setMinimizeHeight(32);
			
			//component creation
			setSize(new IntDimension(368, 232));
			setPreferredSize(new IntDimension(368, 232));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panel13 = new JPanel();
			panel13.setLocation(new IntPoint(8, 2));
			panel13.setSize(new IntDimension(351, 25));
			panel13.setPreferredSize(new IntDimension(351, 25));
			var layout1:FlowWrapLayout = new FlowWrapLayout();
			layout1.setPreferWidth(200);
			layout1.setAlignment(AsWingConstants.LEFT);
			layout1.setHgap(3);
			layout1.setVgap(1);
			layout1.setMargin(true);
			panel13.setLayout(layout1);
			
			btn_tab_slave = new JToggleButton();
			btn_tab_slave.setLocation(new IntPoint(5, 5));
			btn_tab_slave.setSize(new IntDimension(49, 23));
			btn_tab_slave.setPreferredSize(new IntDimension(49, 23));
			btn_tab_slave.setText("奴隶");
			
			btn_tab_lover = new JToggleButton();
			btn_tab_lover.setLocation(new IntPoint(69, 1));
			btn_tab_lover.setSize(new IntDimension(49, 23));
			btn_tab_lover.setPreferredSize(new IntDimension(49, 23));
			btn_tab_lover.setText("情人");
			
			btn_tab_pet = new JToggleButton();
			btn_tab_pet.setLocation(new IntPoint(110, 1));
			btn_tab_pet.setSize(new IntDimension(49, 23));
			btn_tab_pet.setPreferredSize(new IntDimension(49, 23));
			btn_tab_pet.setText("宠物");
			
			panelOption0 = new PaneHomeDispatchOption();
			panelOption0.setLocation(new IntPoint(23, 30));
			panelOption0.setSize(new IntDimension(97, 135));
			panelOption0.setPreferredSize(new IntDimension(97, 135));
			
			panelOption1 = new PaneHomeDispatchOption();
			panelOption1.setLocation(new IntPoint(135, 30));
			panelOption1.setSize(new IntDimension(97, 135));
			panelOption1.setPreferredSize(new IntDimension(97, 135));
			
			panelOption2 = new PaneHomeDispatchOption();
			panelOption2.setLocation(new IntPoint(247, 30));
			panelOption2.setSize(new IntDimension(97, 135));
			panelOption2.setPreferredSize(new IntDimension(97, 135));
			
			panelBCenter = new JPanel();
			panelBCenter.setLocation(new IntPoint(132, 169));
			panelBCenter.setSize(new IntDimension(104, 24));
			panelBCenter.setPreferredSize(new IntDimension(104, 24));
			var layout2:FlowWrapLayout = new FlowWrapLayout();
			layout2.setPreferWidth(200);
			layout2.setAlignment(AsWingConstants.CENTER);
			layout2.setHgap(5);
			layout2.setVgap(0);
			layout2.setMargin(false);
			panelBCenter.setLayout(layout2);
			
			btnPrev = new JButton();
			btnPrev.setLocation(new IntPoint(4, 0));
			btnPrev.setSize(new IntDimension(29, 24));
			btnPrev.setPreferredSize(new IntDimension(29, 24));
			btnPrev.setText("label");
			
			labelPage = new JLabel();
			labelPage.setLocation(new IntPoint(33, 4));
			labelPage.setSize(new IntDimension(36, 16));
			labelPage.setPreferredSize(new IntDimension(36, 16));
			labelPage.setText("label");
			
			btnNext = new JButton();
			btnNext.setLocation(new IntPoint(75, 0));
			btnNext.setSize(new IntDimension(29, 24));
			btnNext.setPreferredSize(new IntDimension(29, 24));
			btnNext.setText("label");
			
			//component layoution
			getContentPane().append(panel13);
			getContentPane().append(panelOption0);
			getContentPane().append(panelOption1);
			getContentPane().append(panelOption2);
			getContentPane().append(panelBCenter);
			
			panel13.append(btn_tab_slave);
			panel13.append(btn_tab_lover);
			panel13.append(btn_tab_pet);
			
			panelBCenter.append(btnPrev);
			panelBCenter.append(labelPage);
			panelBCenter.append(btnNext);
			setImages();
			addEventListener(AWEvent.SHOWN,FrameHomeBuilding.onSecondFrameShown);
			addEventListener(FrameEvent.FRAME_CLOSING,FrameHomeBuilding.onSecondFrameClosing);
			addEventListener(AWEvent.HIDDEN,FrameHomeBuilding.onSecondFrameClosing);
		}
		public function getDispatchPartnerType():int
		{
			if(btn_tab_slave.isSelected())
				return PanelMain.PARTNER_TYPE_SLAVE;
			if(btn_tab_lover.isSelected())
				return PanelMain.PARTNER_TYPE_LOVER;
			if(btn_tab_pet.isSelected())
				return PanelMain.PARTNER_TYPE_PET;
			return PanelMain.PARTNER_TYPE_NULL;
		}
		private var _mallItems:Array = new Array();
		public function setImages():void
		{
			
			var img_char_background:DisplayObject = Client.getUIElement("img_home_dispatch_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_char_background));
			setSize(new IntDimension(img_char_background.width, img_char_background.height));
			setPreferredSize(new IntDimension(img_char_background.width, img_char_background.height));
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
			
			//panelBHImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_default_image") as DisplayObject));
			//panelGuardImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_default_image") as DisplayObject));
			
			btn_tab_slave.wrapSimpleButton(Client.getUIElement("btn_2") as SimpleButton);
			btn_tab_lover.wrapSimpleButton(Client.getUIElement("btn_2") as SimpleButton);
			btn_tab_pet.wrapSimpleButton(Client.getUIElement("btn_2") as SimpleButton);
		
			_mallItems.push(panelOption0);
			_mallItems.push(panelOption1);
			_mallItems.push(panelOption2);
			
			btn_tab_slave.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_tab_slave.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_tab_lover.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_tab_lover.setVerticalTextPosition(AsWingConstants.CENTER);
			btn_tab_pet.setHorizontalTextPosition(AsWingConstants.CENTER);
			btn_tab_pet.setVerticalTextPosition(AsWingConstants.CENTER);
			
			btn_tab_slave.setSelected(true);
			var groupBagTabs:ButtonGroup = new ButtonGroup();
			groupBagTabs.appendAll(btn_tab_slave,btn_tab_lover,btn_tab_pet);
			
			
			//btn_tab_slave.setName(
			
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 5);
			btn_tab_slave.setFont(font);
			btn_tab_slave.setForeground(ASColor.WHITE);
			btn_tab_slave.setTextFilters(new Array(filter));
			
			btn_tab_lover.setFont(font);
			btn_tab_lover.setForeground(ASColor.WHITE);
			btn_tab_lover.setTextFilters(new Array(filter));
			
			btn_tab_pet.setFont(font);
			btn_tab_pet.setForeground(ASColor.WHITE);
			btn_tab_pet.setTextFilters(new Array(filter));
			
			getContentPane().setClipMasked(false);
			setClipMasked(false);
			
			btnPrev.setText("");
			btnNext.setText("");
			
			btnPrev.wrapSimpleButton(Client.getUIElement("btn_prev") as SimpleButton);
			btnNext.wrapSimpleButton(Client.getUIElement("btn_next") as SimpleButton);
			
			btnPrev.addActionListener(onBtnPrev);
			btnNext.addActionListener(onBtnNext);
			font = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelPage.setForeground(ASColor.WHITE);
			labelPage.setFont(font);
			labelPage.setTextFilters(new Array(filter));
			btn_tab_slave.addActionListener(onBtnSlave);
			btn_tab_lover.addActionListener(onBtnLover);
			btn_tab_pet.addActionListener(onBtnPet);
		}
		private function onBtnSlave(event:Event):void
		{
			_currentPageIndex = 0;
			updatePage();
		}
		private function onBtnLover(event:Event):void
		{
			_currentPageIndex = 0;
			updatePage();
		}
		private function onBtnPet(event:Event):void
		{
			_currentPageIndex = 0;
			updatePage();
		}
		private var _currentPageIndex:int = 0;
		private var _currentPageIndexAll:int = 0;
		private var _itemsPerPage:int = 3;
		public function updatePage():void
		{
			for each(var obj:Object in _mallItems)
			{
				obj.item = null;
			}
			var nIndex:int = 0;
			var nCount:int = 0;
			var array:Array = [];
			if(btn_tab_slave.isSelected())
				array = CharInfo.m_arSlaves;
			if(btn_tab_lover.isSelected() && CharInfo.objLover.m_nCharId != 0)
				array = [CharInfo.objLover];
			if(btn_tab_pet.isSelected())
				array = CharInfo.m_arPets;
			for each(var item:Object in array)
			{
				nCount++;
				if(nCount <= _currentPageIndex*_itemsPerPage)
					continue;
				_mallItems[nIndex++].item = item;
				if(nIndex >= _itemsPerPage)
					break;
			}
			
			var nCount1:int = array.length;
			_currentPageIndexAll = Math.floor((nCount1+_itemsPerPage-1)/_itemsPerPage);
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
			btnPrev.setEnabled(_currentPageIndex > 0 &&  _currentPageIndexAll > 1);
			btnNext.setEnabled(_currentPageIndex < _currentPageIndexAll-1 &&  _currentPageIndexAll > 1);
		}
		
		private function onBtnPrev(event:Event):void
		{
			_currentPageIndex--;
			if(_currentPageIndex < 0)
				_currentPageIndex = 0;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
		}
		private function onBtnNext(event:Event):void
		{
			_currentPageIndex++;
			if(_currentPageIndex > _currentPageIndexAll-1)
				_currentPageIndex = _currentPageIndexAll-1;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
		}
		public var objDest:ObjectHomeBuilding = null;
		public static var _frame:FrameHomeDispatch = null;
		public static var _frameParent:FrameHomeBuilding = null;
		public static function show(obj:ObjectHomeBuilding,frameHomeBuilding:FrameHomeBuilding):void
		{
			if(isShowing())
			{
				_frame.hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameHomeDispatch();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			if(FrameHomeAccelerate.isShowing())
				FrameHomeAccelerate.hide();
			
			_frame.show();
			_frame.objDest = obj;
			_frame.setLocationXY((Engine.W - _frame.width) / 2,(Engine.H - _frame.height)/2);
			_frame.updatePage();
			PanelMainHelp.getInstance().bringToTop(_frame);
			
			_frameParent = frameHomeBuilding;
			
			var teamDestX:int = (Engine.W - (_frame.width+frameHomeBuilding.width))/2;
			var teamDestY:int = (Engine.H - frameHomeBuilding.height)/2;
			
			var listDestX:int = teamDestX + frameHomeBuilding.width;
			var listDestY:int = teamDestY + (frameHomeBuilding.height - _frame.height)/2;
			
			var tween:TweenLite = TweenLite.to(frameHomeBuilding, 0.3, {x:teamDestX, y:teamDestY});
			var list_tween:TweenLite = TweenLite.to(_frame, 0.3, {x:listDestX, y:listDestY});
			

			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}
import com.*;
import com.Home.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;
/**
 * MyPaneHomeDispatchOption
 */
class PaneHomeDispatchOption extends JPanel{
	
	//members define
	private var panelImage:JPanel;
	private var labelName:JLabel;
	private var labelLevel:JLabel;
	private var btn_dispatch:JButton;
	
	/**
	 * MyPaneHomeDispatchOption Constructor
	 */
	public function PaneHomeDispatchOption(){
		//component creation
		setSize(new IntDimension(97, 135));
		setPreferredSize(new IntDimension(97, 135));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		panelImage = new JPanel();
		panelImage.setLocation(new IntPoint(14, 4));
		panelImage.setSize(new IntDimension(69, 69));
		panelImage.setPreferredSize(new IntDimension(69, 69));
		
		labelName = new JLabel();
		labelName.setLocation(new IntPoint(2, 77));
		labelName.setSize(new IntDimension(93, 16));
		labelName.setPreferredSize(new IntDimension(93, 16));
		labelName.setText("label");
		
		labelLevel = new JLabel();
		labelLevel.setLocation(new IntPoint(2, 93));
		labelLevel.setSize(new IntDimension(93, 16));
		labelLevel.setPreferredSize(new IntDimension(93, 16));
		labelLevel.setText("label");
		
		btn_dispatch = new JButton();
		btn_dispatch.setLocation(new IntPoint(24, 110));
		btn_dispatch.setSize(new IntDimension(49, 23));
		btn_dispatch.setPreferredSize(new IntDimension(49, 23));
		btn_dispatch.setText("派遣");
		
		//component layoution
		append(panelImage);
		append(labelName);
		append(labelLevel);
		append(btn_dispatch);
		
		
		btn_dispatch.wrapSimpleButton(Client.getUIElement("btn_2") as SimpleButton);
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 5);
		btn_dispatch.setFont(font);
		btn_dispatch.setForeground(ASColor.WHITE);
		btn_dispatch.setTextFilters(new Array(filter));
		
		font = new ASFont("宋体", 12, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		labelName.setForeground(ASColor.WHITE);
		labelName.setFont(font);
		labelName.setTextFilters(new Array(filter));
		labelLevel.setForeground(ASColor.WHITE);
		labelLevel.setFont(font);
		labelLevel.setTextFilters(new Array(filter));
		//panelImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_default_image") as DisplayObject));
		panelImage.setBackgroundDecorator(null);
		btn_dispatch.addActionListener(onBtnDispatch);

	}
	private function onBtnDispatch(e:Event):void
	{
		FrameHomeDispatch.hide();
		Client.getInstance().sendPacketLogic(1303,[int(FrameHomeDispatch._frame.objDest.buildingHomeId),int(0),FrameHomeDispatch._frame.getDispatchPartnerType(),int(_item.m_nInnerId)]);
	}
	
	//_________getters_________
	private var _item:Object = null;
	public function set item(val:Object):void
	{
		_item = val;
		
		labelName.setText("");
		labelLevel.setText("");
		panelImage.setBackgroundDecorator(null);
		btn_dispatch.setVisible(false);
		
		if(_item == null)
		{
			return;
		}

		labelName.setText(_item.m_szCharName);
		labelLevel.setText('Lv.' + _item.m_nLevel);
		panelImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_head") as DisplayObject));
		btn_dispatch.setVisible(true);
		pack();
		this.paintImmediately();
	}
	public function get item():Object
	{
		return _item;
	}
}